<?php
/**
 * Created by IntelliJ IDEA.
 * User: Fernando
 * Date: 22/10/2014
 * Time: 08:36
 */

namespace Fiestissima\CRM\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;

class OrdenCompraProductoType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('orden_compra_producto_id', 'text')
            ->add('orden_compra_producto_cantidad', 'choice', array('choices' => array('1'=>'1',
                '2'=>'2',
                '3'=>'3',
                '4'=>'4',
                '5'=>'5',
                '6'=>'6',
                '7'=>'7',
                '8'=>'8',
                '9'=>'9',
                '10'=>'10',
                '11'=>'11',
                '12'=>'12',
                '13'=>'13',
                '14'=>'14',
                '15'=>'15')))
            ->add('producto', 'entity', array('class' => 'FiestissimaCRM:Producto',
                'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('p')
                            ->orderBy('p.pr_nombre', 'ASC');
                    }, 'expanded' => false, 'multiple' => false))
            ->add('orden_compra', 'entity', array('class' => 'FiestissimaCRM:OrdenCompra',
                'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('op')
                            ->orderBy('op.orden_compra_fecha', 'ASC');
                    }, 'expanded' => false, 'multiple' => false));
    }

    public function getName()
    {
        return 'ordenCompraProducto';
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Fiestissima\CRM\Entity\OrdenCompraProducto',
        ));
    }
} 